﻿@model web.core.ViewModels.ShoppingCartViewModels

@using web.core
@using web.core.Models
@using web.bussines
@using web.component
@{  
    var url_shopping_cart_prefix = "/gio_hang.ub";
    var url_check_out = "/dang_nhap_thanh_toan.ub";
    var total = 0;
    if (Model != null)
    {
        total = Model.CartCount;
    }              

    Html.EnableClientValidation(); 
    using (Html.BeginForm()) {
 <div id="mini-cart" >
                    
    <div class="block-title clearer">   
    	<div class="heading" title="Giỏ hàng của bạn">Giỏ hàng</div>        
        <a class="summary" href="javascript:OpenMiniCart();" title="Giỏ hàng">						            
            	<p class="amount">Giỏ hàng <span id="countID">(
                @if (Model != null) {
                    if (Model.CartItems.Count() > 0)
                    {
                        Html.Raw(Model.CartCount.ToString());
                    }
                    else { Html.Raw("0"); }
                } 
                  )</span></p>
                <p class="subtotal"> sản phẩm @*<span class="price" id="totalID"><% if(Model!=null){ if(Model.CartItems.Count() > 0){ Response.Write(Model.CartTotal + " đ"); }else{ } } %></span>*@</p>			        
        </a> <!-- end: summary -->
    </div> <!-- end: block-title -->   
    <div id="block_style"></div>   
    <div class="block-content block" id="cart_mini" style="width:600px">
        <div class="block-content-inner">
                            
            <p class="block-subtitle"><strong>Bạn có <span id="countID2">
            @if (Model != null) {
                if (Model.CartItems.Count() > 0)
                { 
                    Html.Raw(Model.CartCount.ToString());
                }
                else { Html.Raw("0"); }
            } 
              </span> sản phẩm trong giỏ hàng</strong></p>
            <ol id="cart-sidebar" class="mini-products-list">
               
                @for (int i = 0; i < Model.CartItems.Count(); i++) {
                       var _product = web.core.Models.productModels.GetProductViewByID(Model.CartItems.ElementAt(i).product_id ?? 0,Request.Url.PathAndQuery);
                       if (_product != null) {
                           var p_alias = _product.product_alias != null ? _product.product_alias : "";
                           var p_id = _product.product_id;
                           var p_name = _product.product_name != null ? _product.product_name : "";
                           var p_images = _product.images != null ? _product.images : "";
                           var p_qty = _product.quantity != null ? _product.quantity : 0;
                           var p_price = _product.price != null ? _product.price : 0;
                           var alias_cate = "san_pham";
                           var link = string.Format("/{0}/{1}_{2}", alias_cate, p_alias, p_id);
                           var price_text = Ustring.GetMoney(p_price); 
                       
                                <li class="item" id="row-@(Model.CartItems.ElementAt(i).record_id)">
                                    <a href="@link" title="@p_name " class="product-image"><img src="@p_images" width="50" height="50" alt="@p_name" /></a>
                                    <div class="product-details">                                       
                                        <a title="Xóa khỏi giỏ hàng" onclick="removeFormCart(@Model.CartItems.ElementAt(i).count, @Model.CartItems.ElementAt(i).product_id , @Model.CartItems.ElementAt(i).record_id)" class="btn-remove">Xóa khỏi giỏ hàng</a>
                                        @*<a title="Cập nhật" onclick="UpdateCart();" class="btn-edit">Cập nhật</a>*@
                                        <p class="product-name"><a href="@link">@p_name</a></p>
                                        @*<input id="noqty_<%=p_id %>" value="<%=Model.CartItems.ElementAt(i).count.Value %>" record="<%=Model.CartItems.ElementAt(i).record_id %>" size="4" title="Số lượng" pqty="input_quantity" class="input-text qty" maxlength="12" />*@
                                        <strong id="product_count_@(p_id)">@Model.CartItems.ElementAt(i).count.Value</strong> x <span class="price">@price_text</span>                      
                                        <input id="NoHidden@(Model.CartItems.ElementAt(i).product_id)" type="hidden" value="@p_qty" />                    
                                    </div>
                                </li>
                           }
                    }
            </ol>
   
            <div class="actions">

                <button type="button" title="Tiếp tục mua hàng" id="btn_next" class="button btn-inline" onclick="$.fancybox.close();">
                    <span><span>Tiếp tục mua hàng</span></span>
                </button>
                <button type="button" title="Chi tiết giỏ hàng của bạn" id="btn_cart_detail" class="button btn-inline" onclick="checkNumberCart();">
                    <span><span>Giỏ hàng chi tiết</span></span>
                </button>                  
                <button type="button" title="Thanh toán ngay" id="btn_check_out" class="button btn-checkout btn-inline " onclick="go_to_check_out();">
                    <span><span>Thanh toán ngay</span></span>
                </button>
			</div>
 
			</div> <!-- end: block-content-inner -->
    </div> <!-- end: block-content -->
        
 </div>
    }
}
 <div class="after-mini-cart"></div>